
#include "lv_demo_encoder.h"
#include "lv_port_indev.h"
#include <lvgl.h>
#include "images.h"
 

lv_obj_t *wc_scr[4];

lv_obj_t *weather_image = NULL;
lv_obj_t *cityname_label = NULL;
lv_obj_t *temperature_label = NULL;
lv_obj_t *time_image = NULL;
lv_obj_t *time_image1 = NULL;
lv_obj_t *date_label = NULL;
lv_obj_t *time_label = NULL;

lv_obj_t *mood_image = NULL;


static lv_style_t default_style;
static lv_style_t label_style1;
static lv_style_t label_style2;
static lv_style_t label_style3;



lv_font_declare(lv_font_montserrat_24);
lv_font_declare(lv_font_montserrat_40);


  
const void *image_map[] = {&bukaixin, &kaixin,&yitou,&remen,&mi,&sipi,&wutu,&liuk,&qika};
int map_index[] = {0, 1,2,3,4,5,6,7,8};



void weather_gui_init(void)
{
    lv_style_init(&default_style);
    lv_style_set_bg_color(&default_style, LV_STATE_DEFAULT, LV_COLOR_BLACK);
    lv_style_set_bg_color(&default_style, LV_STATE_PRESSED, LV_COLOR_GRAY);
    lv_style_set_bg_color(&default_style, LV_STATE_FOCUSED, LV_COLOR_BLACK);
    lv_style_set_bg_color(&default_style, LV_STATE_FOCUSED | LV_STATE_PRESSED, lv_color_hex(0xf88));

    // 天气页初始化
    wc_scr[0] = lv_obj_create(NULL, NULL);
    lv_obj_add_style(wc_scr[0], LV_BTN_PART_MAIN, &default_style);
    
    lv_style_init(&label_style1);
    lv_style_set_text_opa(&label_style1, LV_STATE_DEFAULT, LV_OPA_COVER);
    lv_style_set_text_color(&label_style1, LV_STATE_DEFAULT, LV_COLOR_WHITE);
    lv_style_set_text_font(&label_style1, LV_STATE_DEFAULT, &lv_font_montserrat_24);
    lv_style_init(&label_style2);
    lv_style_set_text_opa(&label_style2, LV_STATE_DEFAULT, LV_OPA_COVER);
    lv_style_set_text_color(&label_style2, LV_STATE_DEFAULT, LV_COLOR_WHITE);
    lv_style_set_text_font(&label_style2, LV_STATE_DEFAULT, &lv_font_montserrat_40);

    // 日期时间页初始化
    wc_scr[1] = lv_obj_create(NULL, NULL);
    lv_obj_add_style(wc_scr[1], LV_BTN_PART_MAIN, &default_style);
    
    lv_style_init(&label_style3);
    lv_style_set_text_opa(&label_style3, LV_STATE_DEFAULT, LV_OPA_COVER);
    lv_style_set_text_color(&label_style3, LV_STATE_DEFAULT, LV_COLOR_WHITE);
    lv_style_set_text_font(&label_style3, LV_STATE_DEFAULT, &lv_font_montserrat_40);
    
    
}

void display_weather_time_init()
{
    lv_obj_t *act_obj = lv_scr_act(); // 获取当前活动页
    if (act_obj == wc_scr[0])
        return;
      
    lv_obj_clean(act_obj); // 清空此前页面
    weather_image = lv_img_create(wc_scr[0], NULL);
    cityname_label = lv_label_create(wc_scr[0], NULL);
    temperature_label = lv_label_create(wc_scr[0], NULL);
    time_image = lv_img_create(wc_scr[0], NULL);
    time_image1 = lv_img_create(wc_scr[0], NULL);
    date_label = lv_label_create(wc_scr[0], NULL);
    time_label = lv_label_create(wc_scr[0], NULL);
}

void display_weather_time(const char *page, const char *temperature,const char *date, const char *time,int weed)
{      
    display_weather_time_init();
    lv_img_set_src(weather_image,&tian);
    lv_obj_align(weather_image, NULL, LV_ALIGN_OUT_TOP_MID, 60, 180);

    lv_obj_add_style(cityname_label, LV_LABEL_PART_MAIN, &label_style1);
    lv_label_set_text(cityname_label, page);
    lv_obj_set_pos(cityname_label,0,80);

    lv_obj_add_style(temperature_label, LV_LABEL_PART_MAIN, &label_style2);
    lv_label_set_text_fmt(temperature_label, "%s°C", temperature);
    lv_obj_set_pos(temperature_label,128,0);
    
      const void *path ;
    lv_img_set_src(time_image, &timll);
    lv_obj_align(time_image, NULL, LV_ALIGN_OUT_TOP_MID, 60, 110);
    
    if(weed < 5 ){
      path = image_map[map_index[0]];
      
      }
     else{
      
       path = image_map[map_index[1]];
      }
    
    lv_img_set_src(time_image1, path);
    lv_obj_set_pos(time_image1,0,0);

    lv_obj_add_style(date_label, LV_LABEL_PART_MAIN, &label_style3);
    lv_label_set_text(date_label, date);
    lv_obj_align(date_label, NULL, LV_ALIGN_OUT_BOTTOM_LEFT, 15, -95);

    lv_obj_add_style(time_label, LV_LABEL_PART_MAIN, &label_style3);
    lv_label_set_text(time_label, time);
    lv_obj_align(time_label, NULL, LV_ALIGN_OUT_BOTTOM_LEFT, 15, -50);
    
    
}



void display_mood_init()
{
    lv_obj_t *act_obj = lv_scr_act();
    if (act_obj == wc_scr[1])
        return;
    
    lv_obj_clean(act_obj); // 清空此前页面
    mood_image = lv_img_create(wc_scr[1], NULL);
    
   
}


void display_mood(int wed){
  
    display_mood_init();
     const void *path ;
   switch(wed){
   case 1:path = image_map[map_index[2]];
              break;
   case 2:path = image_map[map_index[3]];
              break;
   case 3:path = image_map[map_index[4]];
     
             break;
   case 4:path = image_map[map_index[5]];
     
      break;
   case 5:path = image_map[map_index[6]];
    
      break;
   case 6:path = image_map[map_index[7]];
     
      break;
   case 7:path = image_map[map_index[8]];
     
      break;
 
   }

    
    lv_img_set_src(mood_image, path);
    lv_obj_align(mood_image, NULL, LV_ALIGN_CENTER, 0, 0);
    
  
  }
